<template>
    <div class="layout">
        <div class="layout" ref="MapView"></div>
        <div class="control">
            <RadioGroup v-model="type" type="button">
                <Radio label="小数"></Radio>
                <Radio label="度分秒"></Radio>
            </RadioGroup>
            <br><br>
            经度 ： <span>{{longitude}}</span>
            <br>
            纬度 ： <span>{{latitude}}</span>
            <br>
            高度 ： <span>{{height}}</span>
        </div>
    </div>
</template>
<script>
import simpleMap from '@best/libs-cli/simpleMap/index.js'

var map = null;
var mapConfig = [{
    "type": "TD",
    "name": "天地图",
    "layerType": "background",
    "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
    "default": false
}]
export default {
    data() {
        return {
            type: '小数',
            longitude: '',
            latitude: '',
            height: '',
        }
    },
    mounted() {
        map = simpleMap.initMap(this.$refs.MapView);
        map.addProviders(mapConfig);
        map.on('MouseMove', (item) => {
            if (this.type == '小数') {
                this.longitude = item.longitude.toFixed(3);
                this.latitude = item.latitude.toFixed(3);
                this.height = item.height.toFixed(3);
            } else {
                this.longitude = simpleMap.util.ToDegrees(item.longitude + '');
                this.latitude = simpleMap.util.ToDegrees(item.latitude + '');
                this.height = item.height.toFixed(3);
            }
        });
    },
    methods: {

    },
    beforeDestroy() {
        // 页面被注销时，销毁地图
        map && map.destroy();
    }
}
</script>

<style scoped>
.layout {
    height: 100%;
    width: 100%;
}

.control {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.4);
    padding: 10px 20px;
    color: #fff;
}
.title {
    color: #fff;
}
</style>